#ifndef __CONNECTION_MANAGER_H__
#define __CONNECTION_MANAGER_H__

#include <cstdint>
#include <map>
#include <set>
#include <vector>
#include <memory>

#include "BS_thread_pool.hpp"
#include "Engine/GameGuid.h"
#include "SimpleSingleton.hpp"
#include "GameEnum.h"
#include "GameType.h"
#include "concurrentqueue.h"

using namespace PocketSurvival::Engine;

namespace PocketSurvival
{
    class ConnectionRequestPackage;

    class ConnectionManager : public SimpleSingletonItem
    {
        friend class SimpleSingleton;
    private:
        float m_waitTime;

        moodycamel::ConcurrentQueue<ClientPtr> m_waitSyncGuidQueue;
        moodycamel::ConcurrentQueue<ClientPtr> m_waitLoadProjectQueue;

    private:
        ConnectionManager();
        ~ConnectionManager() = default;
        ConnectionManager(const ConnectionManager &) = delete;
        ConnectionManager(ConnectionManager &&) = delete;
        ConnectionManager &operator=(const ConnectionManager &) = delete;
        ConnectionManager &operator=(ConnectionManager &&) = delete;

    public:
        bool handleNewRequest(ConnectionRequestPackage *connectionPackage, std::string &rejectMessage);
        
        void update(float dt);

        void syncGuidList(ClientPtr &client);

        inline void addLoadProject(ClientPtr &client);
        inline void addSyncGuid(ClientPtr &client);

        void load();
        void save();
    };

    inline void ConnectionManager::addLoadProject(ClientPtr &client)
    {
        m_waitLoadProjectQueue.enqueue(client);
    }
    inline void ConnectionManager::addSyncGuid(ClientPtr &client)
    {
        m_waitSyncGuidQueue.enqueue(client);
    }


} // namespace PocketSurvival


#endif
